<?php
	class Center_model extends CI_model
		{
			function menu(){
				$data =$this->db->query("select * from menu where khoa=1 order by vi_tri");
				return $data->result_array();
			}
			
			function timkiem1(){
				$data =$this->db->query("select diem_khoi_hanh from tour where trang_thai=1 ");
				return $data->result_array();
			}
			function timkiem2(){
				$data =$this->db->query("select ten_tour from tour where  trang_thai=1 ");
				return $data->result_array();
			}
			
			function danhmuctour(){
				$data =$this->db->query("select * from danhmuctour where trang_thai=1");
				return $data->result_array();
			}
			
			function gettours($iddm){
				$data =$this->db->query("select ct.id_tour,ten_tour,anh_dai_dien from  chitietdanhmuctour ct left join tour t on ct.id_tour = t.id_tour where ct.id_danhmuc = '".$iddm."' ");
				return $data->result_array();
			}
			
			function tour($id_dm){
			$ngay = getdate();
			$currentDate = $ngay["year"] . "-" . $ngay["mon"] . "-" . $ngay["mday"];
			$this->db->select("*");
//			$data = $this->db->query("select top 6, tour.id_tour, ten_tour, ngay_bat_dau, anh_dai_dien 
//										from tour, chitietdanhmuctour, chuyendi 
//										where tour.id_tour=chitietdanhmuctour.id_tour and tour.id_tour=chuyendi.id_tour and tour.trang_thai=true and DATEDIFF('".$currentDate."',chuyendi.ngay_bat_dau ) < -5 and id_danhmuc=".$id_dm."");
			//$data=$this->db->get('tour',6);
			$this->db->from("chitietdanhmuctour");
			$this->db->join("tour","tour.id_tour=chitietdanhmuctour.id_tour","Inner");
			$this->db->join("chuyendi","chuyendi.id_tour=tour.id_tour","Inner");
			$this->db->where("tour.trang_thai",1);
			
			$this->db->where("DATEDIFF('".$currentDate."',chuyendi.ngay_bat_dau ) < -5");
			$this->db->where("id_danhmuc",$id_dm);
			$this->db->limit(6);
			$data = $this->db->get();
			return $data->result_array();
		}
			
			function danhmuctour_right($id){
				
				$this->db->join('tour', 'tour.id_tour = chuyendi.id_tour');
				$this->db->join('chitietdanhmuctour', 'chuyendi.id_tour = chitietdanhmuctour.id_tour');
				$this->db->where('chuyendi.',$id);
				//$this->db->where('chiendi.ngaygido',dieukiengi);
				$data=$this->db->get('chuyendi');
				//var_dump($data->result_array());die;
				return $data->result_array();
		}
		
		
			function load_diemkhoihanh()
			{ 
				$this->db->select('diem_khoi_hanh');
				$this->db ->group_by('diem_khoi_hanh');
				$data=$this->db->get('tour');
				return $data->result_array();
			}
			function load_tour($diemkhoihanh)
			{
				$this->db->select('ten_tour');	
				$this->db->like('diem_khoi_hanh', $diemkhoihanh);
				$data=$this->db->get('tour');
				return $data->result_array();
			}
			//
			function timkiem($keysearch)
			{
				$dulieu = $this->db->select('ten_tour,mo_ta,anh_dai_dien')
										->where('diem_khoi_hanh',$keysearch['sltdiemkhoihanh'])
										->where('ten_tour',$keysearch['slttour'])
										->get('tour')->row();
				return $dulieu;
			}
			/*function timkiem()
			{
				$data= $this->input->get();
				$query1=null;
				if(!empty($data['sltdiemkhoihanh'])&&!empty($data['slttour']))
				{	
					$query1=$this->db->query("SELECT `ten_tour` ,`mo_ta` FROM `tour` WHERE `id_tour`='".$data['sltdiemkhoihanh']."' and  `id_tour` = '".$data['slttour']."'") ;
				}else if(!empty($data['sltdiemkhoihanh']))
				{
					$query1=$this->db->query("SELECT `ten_tour` ,`mo_ta` FROM `tour` WHERE `id_tour`='".$data['sltdiemkhoihanh']."' and  `id_tour` = '".$data['slttour']."'")  ;
				}
				
				
				$data =$query1->num_rows();
				return $data;
			
			
				
			}*/
			
			
			//Phần thông báo tin tức
		
		function count_tt(){
			$data =$this->db->query("select * from tintucthongbao");
			return $data->num_rows();
		}
		
		//function getall1($currentPage, $number){
//			
//			$this->db->limit($number, $currentPage);
//			$data = $this->db->query("select id_tin,tieu_de,hinh_anh,noi_dung,ngay_dang,ho_ten from tintucthongbao, taikhoan where tintucthongbao.ten_tk=taikhoan.ten_tk");
//			//$data =$this->db->get("tintucthongbao");
//			return $data->result_array();
//		}
		
		function getall1($currentPage, $number){
			
			$limit = $this->db->limit($number, $currentPage);
			$this->db->select('id_tin,tieu_de,noi_dung,hinh_anh,ngay_dang,ho_ten');
			$this->db->from('tintucthongbao');
			
			$this->db->join('taikhoan', 'taikhoan.ten_tk = tintucthongbao.ten_tk','Inner');
			$this->db->order_by('ngay_dang','DESC');
			$data = $this->db->get();
			//$data=$this->db->get('tintucthongbao.id_tin, tintucthongbao.tieu_de, tintucthongbao.hinh_anh, tintucthongbao.noi_dung, tintucthongbao.ngay_dang, tintucthongbao.ho_ten');
			return $data->result_array();
		}
		
		function getbyid1($id){
			//$data = $this->db->query("select * from events where id=". $id);
			$this->db->where("id_tin",$id);
			$data = $this->db->get("tintucthongbao");
			return $data->row();
		}
		
		function tt_moinhat(){
			//$data = $this->db->query("select top 3 tieu_de,hinh_anh from tintucthongbao order by tintucthongbao.ngay_dang desc");
			$this->db->select('*');
			$data = $this->db->get('tintucthongbao',5);
			return $data->result_array();
		}
		
			
		}
	?>